package com.huatai.user.controller;

import com.huatai.common.api.R;
import com.huatai.user.entity.Permission;
import com.huatai.user.service.PermissionService;
import com.huatai.user.vo.PermissionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.bouncycastle.pqc.crypto.newhope.NHOtherInfoGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @program: ht-system
 * @description: 资源权限控制器
 * @author: songxiude
 * @create: 2023-02-09 16:19
 **/
@RestController
@RequestMapping("/permission")
@Api(value = "资源权限管理",tags = "资源权限管理")
public class PermissionController {
	@Autowired
	private PermissionService permissionService;

	@PostMapping("/savePermission")
	@ApiOperation(value = "资源权限新增修改（菜单）",notes = "资源权限新增修改（菜单）")
	public R savePermission(@Valid @RequestBody Permission permission){
		return R.status(permissionService.savePermission(permission));
	}

	@GetMapping("/getPermissions")
	@ApiOperation(value = "获取全部资源（菜单）",notes = "获取全部资源（菜单）")
	public R<List<PermissionVo>> getPermissions(){
		return R.data(permissionService.getPermissions());
	}

	@PostMapping("/delPermission")
	@ApiOperation(value = "删除资源权限",notes = "删除资源权限")
	public R delPermission(@ApiParam(name = "permission_id", value = "资源权限id", required = true) @NotBlank(message = "资源权限id不能为空") @RequestParam("permission_id") Long permissionId){
		return R.status(permissionService.delPermission(permissionId));
	}

}
